package net.mukia.web;

import java.util.List;

import javax.annotation.Resource;

import net.mukia.model.Book;
import net.mukia.model.Chapter;
import net.mukia.model.Content;
import net.mukia.service.BookService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/book")
public class BookController {
	
	private Logger logger = LoggerFactory.getLogger(BookController.class);
	
	
	@RequestMapping(value="/list")
	public void list(Model model){
		List<Book> bookList = bookService.queryAllBook(null);
		model.addAttribute("bookList", bookList);
	}
	
	@RequestMapping(value="/chapter/{chapterId}")
	public ModelAndView chapter(Model model,@PathVariable long chapterId){
		Chapter chapter = new Chapter();
		chapter.setId(chapterId);
		Content content = new Content();
		content.setChapter(chapter);
		List<Content> contentList = bookService.queryAllContent(content);
		model.addAttribute("contentList", contentList);
		return new ModelAndView("book/chapter");
	}
	
	@RequestMapping(value="/holybible",method = RequestMethod.GET)
	public String holybible(Model model){
		model.addAttribute("bible", bookService.queryHolyBible());
//		bookService.update();
		return "book/holy_bible";
	}
	
	@Resource
	private BookService bookService;
	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}
}
